/**
 * 常用功能路由
 */
import { guid } from '../utils/jcore/easyHash'
import { aboutLayout, RouterViewLayout } from '../components/layout/index.js'

const commonRoutes = [
  {
    meta: { title: '常用功能', icon: 'icon-danweiguanli' },
    children: [
      {
        path: '/home',
        meta: { title: '首页' },
        component: () => import('@/views/pages/home/home.vue')
      },
      {
        path: '/menu',
        meta: { title: '菜单' },
        component: () => import('@/views/pages/Menu/index.vue')
      },
      // {
      //   path: '/organization',
      //   meta: { title: '机构管理' },
      //   component: () => import('@/views/pages/Organization/index.vue')
      // },
      {
        path: '/realDuty',
        meta: { title: '供应商管理', fatherType: '0', type: '0' },
        component: () => import('@/views/pages/realDuty/index.vue')
      },
      {
        path: '/user',
        meta: { title: '用户管理' },
        component: () => import('@/views/pages/User/index.vue')
      },
      {
        path: '/roles',
        meta: { title: '角色管理' },
        component: () => import('@/views/pages/Roles/index.vue')
      },

      {
        path: '/spIndex',
        meta: { title: '商品管理' },
        component: () => import('@/views/pages/spIndex/index.vue')
      },
      {
        path: '/architecture',
        meta: { title: '建筑咨询管理' },
        component: () => import('@/views/pages/architecture/index.vue')
      },

      {
        path: '/userGroup',
        meta: { title: '工程咨询服务' },
        children: [
          {
            path: '/projectCase',
            meta: { title: '经典案例', fatherType: '0', type: '0' },
            component: () => import('@/views/pages/userGroup/index.vue')
          },
          {
            path: '/projectqualificationHonor',
            meta: { title: '资质荣誉', fatherType: '0', type: '1' },
            component: () => import('@/views/pages/userGroup/index.vue')
          },
          {
            path: '/projectexpertTeam',
            meta: { title: '专家团队', fatherType: '0', type: '2' },
            component: () => import('@/views/pages/userGroup/index.vue')
          }
        ]
      },
      {
        path: '/financeAndTax',
        meta: { title: '财税服务' },
        children: [
          {
            path: '/financeAndTaxCase',
            meta: { title: '经典案例', fatherType: '1', type: '0' },
            component: () => import('@/views/pages/userGroup/index.vue')
          },
          {
            path: '/financeAndTaxqualificationHonor',
            meta: { title: '资质荣誉', fatherType: '1', type: '1' },
            component: () => import('@/views/pages/userGroup/index.vue')
          },
          {
            path: '/financeAndTaxexpertTeam',
            meta: { title: '专家团队', fatherType: '1', type: '2' },
            component: () => import('@/views/pages/userGroup/index.vue')
          }
        ]
      },
      {
        path: '/law',
        meta: { title: '法律服务' },
        children: [
          {
            path: '/lawCase',
            meta: { title: '经典案例', fatherType: '2', type: '0' },
            component: () => import('@/views/pages/userGroup/index.vue')
          },
          {
            path: '/lawqualificationHonor',
            meta: { title: '资质荣誉', fatherType: '2', type: '1' },
            component: () => import('@/views/pages/userGroup/index.vue')
          },
          {
            path: '/lawexpertTeam',
            meta: { title: '专家团队', fatherType: '2', type: '2' },
            component: () => import('@/views/pages/userGroup/index.vue')
          }
        ]
      },
      {
        path: '/zpxx',
        meta: { title: '招聘信息' },
        component: () => import('@/views/pages/zpxx/index.vue')
      },
      {
        path: '/dict',
        meta: { title: '字典管理' },
        component: () => import('@/views/pages/dict/index.vue')
      },
      {
        path: '/zb',
        meta: { title: '招标中心' },

        children: [
          {
            path: '/invitation',
            meta: { title: '工程管理' },
            children: [
              {
                path: '/invitationAll',
                meta: { title: '全部', fatherType: 0, type: 5 },
                component: () => import('@/views/pages/invitation/index.vue')
              },
              {
                path: '/invitationcg',
                meta: { title: '招标/采购公告', fatherType: 0, type: 0 },
                component: () => import('@/views/pages/invitation/index.vue')
              },
              {
                path: '/invitationzb',
                meta: { title: '成交/中标公告', fatherType: 0, type: 1 },
                component: () => import('@/views/pages/invitation/index.vue')
              },
              {
                path: '/invitationbd',
                meta: { title: '补遗/澄清/更正公告', fatherType: 0, type: 2 },
                component: () => import('@/views/pages/invitation/index.vue')
              },
              {
                path: '/invitationfb',
                meta: { title: '废标/终止公告', fatherType: 0, type: 3 },
                component: () => import('@/views/pages/invitation/index.vue')
              },
              {
                path: '/invitationly',
                meta: { title: '履约/合同公告', fatherType: 0, type: 4 },
                component: () => import('@/views/pages/invitation/index.vue')
              }
            ]
          },
          {
            path: '/lawgl',
            meta: { title: '法律管理' },
            children: [
              {
                path: '/invitationlaw',
                meta: { title: '全部', fatherType: 1, type: 5 },
                component: () => import('@/views/pages/invitation/index.vue')
              },
              {
                path: '/purchaselaw',
                meta: { title: '招标/采购公告', fatherType: 1, type: 0 },
                component: () => import('@/views/pages/invitation/index.vue')
              },
              {
                path: '/purchasezb',
                meta: { title: '成交/中标公告', fatherType: 1, type: 1 },
                component: () => import('@/views/pages/invitation/index.vue')
              },
              {
                path: '/purchaseby',
                meta: { title: '补遗/澄清/更正公告', fatherType: 1, type: 2 },
                component: () => import('@/views/pages/invitation/index.vue')
              },
              {
                path: '/purchasefb',
                meta: { title: '废标/终止公告', fatherType: 1, type: 3 },
                component: () => import('@/views/pages/invitation/index.vue')
              },
              {
                path: '/purchasely',
                meta: { title: '履约/合同公告', fatherType: 1, type: 4 },
                component: () => import('@/views/pages/invitation/index.vue')
              }
            ]
          },
          {
            path: '/finance',
            meta: { title: '财税管理' },
            children: [
              {
                path: '/financeTax',
                meta: { title: '全部', fatherType: 2, type: 5 },
                component: () => import('@/views/pages/invitation/index.vue')
              },
              {
                path: '/financeTaxzb',
                meta: { title: '招标/采购公告', fatherType: 2, type: 0 },
                component: () => import('@/views/pages/invitation/index.vue')
              },
              {
                path: '/financeTaxcj',
                meta: { title: '成交/中标公告', fatherType: 2, type: 1 },
                component: () => import('@/views/pages/invitation/index.vue')
              },
              {
                path: '/financeTaxby',
                meta: { title: '补遗/澄清/更正公告', fatherType: 2, type: 2 },
                component: () => import('@/views/pages/invitation/index.vue')
              },
              {
                path: '/financeTaxfb',
                meta: { title: '废标/终止公告', fatherType: 2, type: 3 },
                component: () => import('@/views/pages/invitation/index.vue')
              },
              {
                path: '/financeTaxly',
                meta: { title: '履约/合同公告', fatherType: 2, type: 4 },
                component: () => import('@/views/pages/invitation/index.vue')
              }
            ]
          }
        ]
      }
    ]
  }
]

/**
 * 添加一些必要字段
 * 这些字段便于侧边栏导航等组件使用
 */
let id = 100
function addField(list, level) {
  const siff = process.env.NODE_ENV === 'development' ? '-test' : ''
  for (let node of list) {
    node.meta.menuId = guid()
    if (node.children && node.children.length) {
      node.meta.menuType = 2
      node.name = '' + id
      node.path = '/' + id
      node.component = level > 1 ? RouterViewLayout : aboutLayout
      id++
      addField(node.children, level + 1)
    } else {
      node.meta.menuType = 3
      node.name = node.path.slice(1) + siff
    }
  }
}
addField(commonRoutes, 1)

export { commonRoutes }
